package com.lmb.exception;

import com.lmb.bean.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;
@Slf4j
@RestControllerAdvice
public class ProjectExceptionHandler {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R doException(SQLIntegrityConstraintViolationException e){
        log.error("【全局异常处理器捕获异常：{}】",e.getMessage());
        String msg = e.getMessage();
        String username = msg.split(" ")[2];
        return R.error(username+"已存在！");
    }


}
